package 练习2;

//遍历数组元素所在的位置

import java.util.Scanner;

public class test08 {
    public static void main(String[] args) {
        int[] arr = {11, 22, 33, 44, 55, 66};

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数");
        int number = sc.nextInt();

        int index = getIndex(arr, number);
        System.out.println("index=" + index);
    }

    public static int getIndex(int[] arr, int number) {
        int index = -1;
        for (int x = 0; x < arr.length; x++) {
            if (arr[x] == number) {
                index = x;
                break;
            }
        }
        return index;
    }
}